- /* srmredc.cpp by K.Tsuru */
- // function ID = 801 BRADIX
- /*****************************
- SRational class
- It provides a reducuction.
- *****************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- static const uint initReduceSize = 512u; //initial value of reduceSize
- uint SRational::reduceSize = initReduceSize;
-
- void SRational::reduce(bool must){
- if( !num.Sign(801) ){ SetZero(); return; } //numerator is zero
- if( num.IsOne() || den.IsOne() ) reduceDone = true; //numerator or denominator is one
- if( reduceDone == true ) return;
-
- // reduceDone = false
- //When the number of figures is small it does not reduce.
- if( !must && ( max( num.Head(), den.Head() ) < reduceSize) ) return;
- //To make the reduction as late as possible it divides num and den by 2^b*R^r.
- if( !(num[0] % 2u) && !(den[0] % 2u) ) ReduceByPow2Rdx(num, den);
- if( !must && ( max( num.Head(), den.Head() ) < reduceSize) ) return;
- //reduction
- SLong d = gcdL(num, den); // d > 0, type of d is BIN_INT
- num /= d; den /= d;
- reduceDone = true;
- //When the calculation for large figures continues it enlarges the value of reduceSize.
- uint rds = min(num.Head(), den.Head()) +1u;
- if(rds > reduceSize) reduceSize = min(4u*rds, num.MaxSize());
- else reduceSize = initReduceSize;
- }
srmredc.cpp : last modifiled at 2016/06/30 14:50:55(1,294 bytes)
created at 2016/06/26 15:57:35
The creation time of this html file is 2016/09/18 20:28:05 (Sun Sep 18 20:28:05 2016).